package com.janlei.tdd.lintcode.t_1613;

import lombok.AllArgsConstructor;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class T_1613 {

    public String highestFrequency(String[] ipLines) {
        // Write your code here
        Map<String, Long> map = Arrays.stream(ipLines)
                .collect(Collectors.groupingBy(p -> p, Collectors.counting()));

        List<Node> nodes = new ArrayList<>();
        map.forEach((k,v)-> nodes.add(new Node(k,v)));

        Node node = nodes.stream().min((o1, o2) -> Long.compare(o2.time, o1.time)).orElseThrow(IllegalAccessError::new);
        return node.ip;
    }
}

@AllArgsConstructor
class Node{
    String ip;
    long time;
}